//
//  MWHomeHeaderView.m
//  XiRan-iOS
//
//  Created by Richfit on 2019/10/11.
//  Copyright © 2019 Wood. All rights reserved.
//

#import "MWHomeHeaderView.h"

@interface MWHomeHeaderView ()

@property(nonatomic, strong) UIImageView *markIV;
@property(nonatomic, strong) UILabel *titleLB;
@property(nonatomic, strong) UIButton *filterBtn;

@end

@implementation MWHomeHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupPageSubviews];
    }
    return self;
}

- (void)filterAction:(UIButton *)sender {
    if (self.block) {
        self.block();
    }
}

- (void)setTitleStr:(NSString *)titleStr {
    _titleLB.text = titleStr;
}

- (void)setFilterStr:(NSString *)filterStr {
     [_filterBtn setTitle:filterStr forState:UIControlStateNormal];
     [_filterBtn setIconInRightWithSpacing:10];
}

- (void)setupPageSubviews {
    _markIV = [[UIImageView alloc] init];
    _markIV.image = [UIImage imageNamed:@"ic_mark"];
    [self addSubview:_markIV];
    
    _titleLB = [[UILabel alloc] init];
    _titleLB.font = MWFont(18);
    _titleLB.textColor = MWHexColor(@"#333333");
    [self addSubview:_titleLB];
    
    _filterBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _filterBtn.titleLabel.font = MWBoldFont(16);
    [_filterBtn setTitleColor:MWHexColor(@"#666666") forState:UIControlStateNormal];
    [_filterBtn setTitleColor:MWHexColor(@"#666666") forState:UIControlStateHighlighted];
    [_filterBtn setImage:[UIImage imageNamed:@"ic_filter"] forState:UIControlStateNormal];
    [_filterBtn setImage:[UIImage imageNamed:@"ic_filter"] forState:UIControlStateHighlighted];
    [_filterBtn addTarget:self action:@selector(filterAction:) forControlEvents:UIControlEventTouchUpInside];
    [_filterBtn setIconInRightWithSpacing:10];
    [self addSubview:_filterBtn];

    [_markIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(16);
        make.centerY.equalTo(self);
    }];
    
    [_titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.markIV.mas_right).offset(16);
        make.centerY.equalTo(self);
    }];
    
    [_filterBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-16);
        make.centerY.equalTo(self);
        make.width.equalTo(@50);
    }];
    [_filterBtn setIconInRightWithSpacing:10];
}

@end
